package net.maku.talent.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.talent.convert.HonorCommunityConvert;
import net.maku.talent.entity.HonorCommunityEntity;
import net.maku.talent.service.HonorCommunityService;
import net.maku.talent.query.HonorCommunityQuery;
import net.maku.talent.vo.HonorCommunityVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 集体荣誉
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2025-03-21
*/
@RestController
@RequestMapping("talent/honor_community")
@Tag(name="集体荣誉")
@AllArgsConstructor
public class HonorCommunityController {
    private final HonorCommunityService honorCommunityService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('talent:honor_community:page')")
    public Result<PageResult<HonorCommunityVO>> page(@ParameterObject @Valid HonorCommunityQuery query){
        PageResult<HonorCommunityVO> page = honorCommunityService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('talent:honor_community:info')")
    public Result<HonorCommunityVO> get(@PathVariable("id") Long id){
        HonorCommunityEntity entity = honorCommunityService.getById(id);

        return Result.ok(HonorCommunityConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    @PreAuthorize("hasAuthority('talent:honor_community:save')")
    public Result<String> save(@RequestBody HonorCommunityVO vo){
        honorCommunityService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    @PreAuthorize("hasAuthority('talent:honor_community:update')")
    public Result<String> update(@RequestBody @Valid HonorCommunityVO vo){
        honorCommunityService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('talent:honor_community:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        honorCommunityService.delete(idList);

        return Result.ok();
    }
}